package com.css.fxfzfxqh.modules.vulnerabilityData.cztDataMange.utils;

import com.sun.istack.NotNull;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;

/**
 * 生成编号
 */
@Configuration
public class GenerationNumberUtil {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 流水号
     * @param key
     * @return
     */
    public synchronized String getGenerationNumber(@NotNull String key) {
        String generationNumber = stringRedisTemplate.opsForValue().get(key);
        if (StringUtils.isBlank(generationNumber)) {
            generationNumber = "001";
        } else {
            StringBuilder stringBuilder = new StringBuilder();
            String t = String.valueOf(Integer.parseInt(generationNumber) + 1);
            for (int i = t.length(); i < 3; i++) {
                stringBuilder.append("0");
            }
            generationNumber = stringBuilder.append(t).toString();
        }
        stringRedisTemplate.opsForValue().set(key, generationNumber);
        return generationNumber;
    }

    /**
     * 城市首字母
     */
    public static String getCityInitials(String cityName){
        String result = "";
        if(cityName.equals("北京市"))
            result = "BJ";
        if(cityName.equals("上海市"))
            result = "SH";
        if(cityName.equals("天津市"))
            result = "TJ";
        if(cityName.equals("重庆市"))
            result = "CQ";
        if(cityName.equals("河北省"))
            result = "HE";
        if(cityName.equals("山西省"))
            result = "SX";
        if(cityName.equals("内蒙古自治区"))
            result = "NM";
        if(cityName.equals("辽宁省"))
            result = "LN";
        if(cityName.equals("吉林省"))
            result = "JL";
        if(cityName.equals("黑龙江省"))
            result = "HL";
        if(cityName.equals("江苏省"))
            result = "JS";
        if(cityName.equals("浙江省"))
            result = "ZJ";
        if(cityName.equals("安徽省"))
            result = "AH";
        if(cityName.equals("福建省"))
            result = "FJ";
        if(cityName.equals("江西省"))
            result = "JX";
        if(cityName.equals("山东省"))
            result = "SD";
        if(cityName.equals("河南省"))
            result = "HA";
        if(cityName.equals("湖北省"))
            result = "HB";
        if(cityName.equals("湖南省"))
            result = "N";
        if(cityName.equals("广东省"))
            result = "GD";
        if(cityName.equals("广西壮族自治区"))
            result = "GX";
        if(cityName.equals("海南省"))
            result = "HI";
        if(cityName.equals("四川省"))
            result = "SC";
        if(cityName.equals("贵州省"))
            result = "GZ";
        if(cityName.equals("云南省"))
            result = "YN";
        if(cityName.equals("西藏自治区"))
            result = "XZ";
        if(cityName.equals("陕西省"))
            result = "SN";
        if(cityName.equals("甘肃省"))
            result = "GS";
        if(cityName.equals("青海省"))
            result = "QH";
        if(cityName.equals("宁夏回族自治区"))
            result = "NX";
        if(cityName.equals("新疆维吾尔族自治区"))
            result = "XJ";
        if(cityName.equals("台湾省"))
            result = "TW";
        if(cityName.equals("香港特别行政区"))
            result = "HK";
        if(cityName.equals("澳门特别行政区"))
            result = "M0";
        return result;
    }

    public static String getFs(String fs){
        String result = "";
        if (fs.equals("未设防"))
            result = "W";
        if (fs.equals("其他"))
            result = "Q";
        if (fs.equals("自设防"))
            result = "Z";
        if (fs.equals("6度"))
            result = "6";
        if (fs.equals("7度"))
            result = "7";
        if (fs.equals("8度"))
            result = "8";
        if (fs.equals("9度"))
            result = "9";
        return result;
    }

    public static String type(String a,String b){
        String resultA = "";
        String resultB = "";
        if(a.equals("砌体结构"))
            resultA = "1";
        if(a.equals("钢筋混凝土结构"))
            resultA = "2";
        if(a.equals("土木结构"))
            resultA = "3";
        if(a.equals("钢结构"))
            resultA = "4";
        if(a.equals("工业厂房"))
            resultA = "5";
        if(a.equals("组合结构"))
            resultA = "6";
        if(a.equals("其他"))
            resultA = "7";
        if(b.equals("砖混结构"))
            resultB = "1";
        if(b.equals("石木结构"))
            resultB = "2";
        if(b.equals("砖木结构"))
            resultB = "3";
        if(b.equals("框架结构"))
            resultB = "1";
        if(b.equals("框架-剪力墙结构"))
            resultB = "2";
        if(b.equals("剪力墙结构"))
            resultB = "3";
        if(b.equals("砖混结构厂房"))
            resultB = "1";
        if(b.equals("钢筋混凝土结构厂房"))
            resultB = "2";
        if(b.equals("钢结构厂房"))
            resultB = "3";
        if(!StringUtils.isBlank(resultB)){
            return resultA+"-"+resultB;
        }
        return resultA;
    }
}
